package com.woniu.service.mallSystem.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.woniu.mapper.mallSystem.ChinaMapper;
import com.woniu.model.mallSystem.entity.China;
import com.woniu.service.mallSystem.IChinaService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lzj
 * @since 2023-10-19
 */
@Service
public class ChinaServiceImpl extends ServiceImpl<ChinaMapper, China> implements IChinaService {

    @Override
    @Cacheable(cacheNames = "CITIES_CACHE", key = "#root.methodName + #provinceId")
    public List<China> getAllCities(Integer provinceId) {
        return baseMapper.selectList(Wrappers.lambdaQuery(China.class)
                .eq(Objects.nonNull(provinceId),China::getPid,provinceId));
    }

    @Override
    @Cacheable(cacheNames = "COUNTIES_CACHE", key = "#root.methodName + #cityId")
    public List<China> getAllCounties(Integer cityId) {
        //根据城市加载区域
        return baseMapper.selectList(Wrappers.lambdaQuery(China.class)
                .eq(Objects.nonNull(cityId),China::getPid,cityId));
    }
}
